package com.jrtc.service.impl;

import com.jrtc.base.entity.bo.Hospital;
import com.jrtc.base.entity.bo.LaboratoryReport;
import com.jrtc.base.entity.vo.LaboratoryReportVO;
import com.jrtc.dao.HospitalDao;
import com.jrtc.dao.LaboratoryReportDao;
import com.jrtc.service.HospitalService;
import com.jrtc.service.LaboratoryReportService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service("laboratoryReport")
public class LaboratoryReportServiceImpl implements LaboratoryReportService {
    @Resource
    private LaboratoryReportDao laboratoryReportDao;
    @Resource
    private HospitalDao hospitalDao;

    @Override
    public List<LaboratoryReportVO> queryLaboratoryReports(Integer patientId) {
        List<LaboratoryReportVO> laboratoryReports = new ArrayList<>();
        List<LaboratoryReport> laboratoryReportlist = laboratoryReportDao.queryLaboratoryReports(patientId);
        if (laboratoryReportlist != null && laboratoryReportlist.size() > 0) {
            for (LaboratoryReport laboratoryReport : laboratoryReportlist) {
                LaboratoryReportVO reportVO = new LaboratoryReportVO();
                BeanUtils.copyProperties(laboratoryReport, reportVO);
                Hospital hospital = hospitalDao.hospitalById(laboratoryReport.getHospitalId());
                reportVO.setHospitalName(hospital.getHospitalName());
                laboratoryReports.add(reportVO);
            }
        }
        return laboratoryReports;
    }

    /**
     * 新增实验室报告
     * @param laboratoryReport
     * @return
     */
    @Override
    public int insertLaboratoryReports(LaboratoryReport laboratoryReport) {
        laboratoryReport.setCreateTime(new Date());
        laboratoryReport.setUpdateTime(new Date());
        return laboratoryReportDao.insertLaboratoryReports(laboratoryReport);
    }
}
